package org.example.service;

import org.example.dao.SysUserDao;
import org.example.entity.Supplier;
import org.example.entity.SysUser;
import org.example.tools.jdbcUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SysUserService implements SysUserDao {
    @Override
    public SysUser querySysUser(SysUser sysUser) throws SQLException, ClassNotFoundException {
       //建立连接
        Connection conn = jdbcUtils.getConnection();
        //查询操作
        String sql = "select * from sys_user where name='"+sysUser.getUserName()+"'";
        ResultSet res = jdbcUtils.executeQuery(sql,conn);
        SysUser target = new SysUser();
        while (res.next()){
            target.setId(sysUser.getId());
            target.setUserName(res.getString("name"));
            target.setPassword(res.getString("password"));
            target.setUserRights(res.getString("rights"));
        }
        return target;
    }

    @Override
    public int updateSysUser(SysUser sysUser) throws SQLException, ClassNotFoundException {
        //建立连接
        Connection conn = jdbcUtils.getConnection();
        //查询操作
        String sql = "update sys_user set password='"+sysUser.getPassword()+"',rights='"+sysUser.getUserRights()+"' where id="+sysUser.getId();

        return jdbcUtils.executeUpdate(sql,conn);
    }
}
